// pages/punchCard/punchCard.js
import Time from "../../utils/time"

let Player = require("../../utils/player"),
    audioList = [],
    player = new Player(),
    playerCurrent = {},
    videoContext = {}
const app = getApp();
const api = require('../../utils/interface.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        // 头部信息 图片 名字 参加人数 打卡人数
        cardInfo: {
            imgUrl: 'http://www.haopic.me/wp-content/uploads/2016/10/20161013124719335.jpg',
            name: '五月绿舍离身体整理健身打卡',
            addNumber: '663',
            punchNumber: '3622',
        },
        userInfo: wx.getStorageSync("userInfo"),
        // 当返回的 评论为0 请返回“”

        //    效果控制
        control: {
            audio: {
                player: {},
                id: "",
                isPlayer: true,
                isPause: false,
                startDate: '00:00',
                progress: "",
                activeProgress: {},
                aniProgress: {},
                loadSucc: false
            },
            movieList: [],
            movie: {},
            focus:''
        },
        show: true, // ture 显示打卡 false 显示成员
        userList: [],
        pkid: 0,
        groupInfo: {},
        detailList: [],
        page: 1,
        size: 10,
        user_page: 1,
        isload_d: false,
        isload_u: false,
        poster: '../../images/timg.jpg',
        name: '',
        author: '',
        screenWidth:"",
        screenHeight:'',
        cgaRef: {},
        backImg: "",
        content: "",
        isCanvas:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options.focus);
        var that = this;
        that.setData({
            userInfo: app.globalData.userInfo
        });
        var that = this;
        that.setData({
            pkid: options.id,
            focus:options.focus,
            isCanvas: options.isCanvas !=undefined?'true':'false'
        });
        //加载圈子详情
        // that.get_group_info();
        // //加载圈子包含日记
        // that.get_detail_list();

    },
    //获取圈子详情
    get_group_info: function () {
        var that = this;
        app.Post(api.wxapp.clock_group_info, {
            groupId: that.data.pkid,
            hasPerson: false
        }, function (res) {
            console.log(res)
            if (res.code == 1) {
                that.setData({
                    groupInfo: res.data
                });
            }
        });
    },
    //请求圈子日记列表
    get_detail_list: function () {
        var that = this,
            detailList=this.data.detailList
        app.Post(api.wxapp.clock_detail_list, {
            groupId: that.data.pkid,
            page: that.data.page,
            size: that.data.size
        }, function (res) {
            if (res.code == 1) {
                that.setData({
                    detailList: detailList.concat(res.data.ClockDetailList)
                });
                that.AudioProgress();
                that.initAudio();
                if (res.data.ClockDetailList.length < that.data.size) {
                    that.setData({
                        isload_d: true
                    });
                } else {
                    that.setData({
                        page: that.data.page + 1
                    });
                }
            }
        });
    },
    //获取成员
    get_person_list: function () {
        var that = this,
            userList = this.data.userList;
            if(userList.length == 0 || userList.length == undefined) {
                console.log("进来了 ")
                userList = []
            }
            console.log( userList instanceof Array)
        console.log(userList)
        app.Post(api.wxapp.get_person_list, {
            groupId: that.data.pkid,
            page: that.data.user_page,
            size: that.data.size
        }, function (res) {
            console.log(res.data.PersonList[1])
            res.data.PersonList.forEach(function (item,index) {
                userList.push(item)
            })
            console.log(userList)
            if (res.code == 1) {
                that.setData({
                    userList:userList
                });
                console.log(that.data.userList)
                if (res.data.PersonList.length < that.data.size) {
                    that.setData({
                        isload_u: true
                    });
                } else {
                    that.setData({
                        user_page: that.data.user_page + 1
                    });
                }
            }
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },
    // 点击红心 发送事件
    bindpraise: function (e) {
        if(app.isUserBound() == false){
            return false
        }

        let that = this,
            log = that.data.detailList,
            bind = e.currentTarget.dataset.bind,
            isHeart = log[bind].IsThumbUp,
            userINfo = that.data.userInfo;
        console.log(app.globalData.userInfo);
        var param = {
            detailId: e.currentTarget.dataset.id,
            type: isHeart ? 2 : 1
        };
        app.Post(api.wxapp.clock_detail_thumb, param, function (res) {
            if (res.code == 1) {
                if (!isHeart) {
                    log[bind].ThumbsUpList.push({
                        AccountId: app.globalData.userInfo.Id,
                        Nickname: app.globalData.userInfo.Nickname
                    });
                    console.log(e.currentTarget.dataset.bind)
                    log[bind].IsThumbUp = true
                    log[bind].ThumbsUpCount = log[bind].ThumbsUpCount + 1;
                } else {
                    var thums = [];
                    log[bind].IsThumbUp = false
                    log[bind].ThumbsUpCount = log[bind].ThumbsUpCount - 1;
                    for (var i = 0; i < log[bind].ThumbsUpList.length; i++) {
                        if (log[bind].ThumbsUpList[i].AccountId != app.globalData.userInfo.Id) {
                            thums.push(log[bind].ThumbsUpList[i]);
                        }
                    }
                    log[bind].ThumbsUpList = thums;
                }
                that.setData({
                    detailList: log
                });
            }
        })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.get_group_info();
        if(this.data.isCanvas == 'true'){
            this.group_calender_total()
            this.get_share_info()
        }

        if (this.data.isShuaXing == false) {
            this.setData({
                isShuaXing: true
            })
            return false;
        }
        this.setData({

            detailList: [],
            page: 1,
            size: 10,
            user_page: 1,
            isload_d: false,
            isload_u: false,
        });
        //加载圈子详情

        //加载圈子包含日记
        this.get_detail_list();


    },
    //切换
    bindSwitch: function (e) {
        var that = this;
        console.log(e)
        let bind = e.currentTarget.dataset.bind,
            show = this.data.show;
        if (bind == 1) {
            show = true;
            that.setData({
                page: 1,
                detailList: []
            });
            that.get_detail_list();
        } else {
            show = false;
            that.setData({
                user_page: 1,
                userList: []
            });
            that.get_person_list();
        }
        this.setData({
            show: show
        })
    },
    skip: function (e) {
        console.log(e.currentTarget.dataset.bind)
        let bind = e.currentTarget.dataset.bind
        if (bind == 2) {
            wx.navigateTo({
                url: '../Billboard/Billboard?id=' + e.currentTarget.dataset.id,
            })
        } else {
            wx.navigateTo({
                url: '../calendar/calendar?id=' + e.currentTarget.dataset.id + '&IsTodayClock=' + this.data.groupInfo.IsTodayClock,
            })
        }
    },
    //点击关注
    touchguanZhu: function (e) {
        var that = this,
            bind = e.currentTarget.dataset.bind,
            isthumbe = e.currentTarget.dataset.isthumbe,
            accountid = e.currentTarget.dataset.accountid;
        //添加关注
        if (!e.currentTarget.dataset.isthumbe) {
            app.Post(api.wxapp.follow_add, {
                accountId: accountid
            }, function (res) {
                if (res.code == 1) {
                    app.ShowMsg("关注成功");
                } else {
                    app.WxAlert(res.msg);
                }
            });
        } else {
            //取消关注
            app.Post(api.wxapp.follow_delete, {
                accountId: accountid
            }, function (res) {
                if (res.code == 1) {
                    app.ShowMsg("取消成功");
                } else {
                    app.WxAlert(res.msg);
                }
            });
        }
        //赋值
        if (!isthumbe) {
            that.data.detailList[bind].IsFollowd = true
        } else {
            that.data.detailList[bind].IsFollowd = false
        }
        this.setData({
            detailList: that.data.detailList
        });
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        console.log("下拉")
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        console.log("上拉")
        this.get_detail_list()
        this.get_person_list()
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return {
            title: '测试分享',
            path: 'pages/index/index',
            success: (res) => {
                console.log("转发成功", res);
            },
        }
    },
    // 初始化录音
    initAudio: function () {
        const that = this,
            detailList = that.data.detailList;
        player.list.clear()
        let audioData = []
        console.log(detailList)
        console.log(player.list)
        audioList = []
        for (let i = 0; i < detailList.length; i++) {
            if (detailList[i].ContentRadio != "") {
                audioList.push({
                    id: "aa",
                    dataUrl: detailList[i].ContentRadio,
                    title: i,
                    index: i,
                })
            }
        }
        console.log(audioList)
        player.list.create(audioList)
        console.log(player.list.info())

    },
    //    录音播放实例
    createAudioPlay: function (e) {
        const that = this,
            control = that.data.control,
            time = new Time(),
            isPlayer = control.audio.isPlayer,
            url = e.currentTarget.dataset.bind
        let index;
        for (let j = 0; j < audioList.length; j++) {
            if (audioList[j].index == url) {
                console.log(audioList[j])
                index = audioList[j]._id
            }
        }
        console.log(":-------------------")
        console.log(player.list.info())
        control.audio.id = url
        console.log(index)
        player.list.syncIndex(audioList[index])
        console.log(player.list.current())

        console.log("别的")
        console.log(player.list.current())
        //      判断是否点击当前录音
        if (player.list.current() != null && playerCurrent.index != url) {
            player.stop()
            //    初始化进度条    点击别的录音
            that.audioProgressAnimation(0, control.audio.progress, "00:00")
            // 全部停止

            console.log("开始播放别的-----------")
            setTimeout(function () {
                player.invoke(index)
            }, 100)
            control.audio.isPlayer = false
            that.setData({
                control: control
            })

            player.event.on('timeupdate', function (data) {
                console.log("开始监听")
                if (data.status == 1) {
                    console.log(data)
                    let startDate = time.secondConvertMinute(data.currentPosition)
                    console.log(startDate)
                    let actWidth = parseFloat(data.currentPosition / data.duration)
                    console.log(actWidth)
                    that.audioProgressAnimation(actWidth, control.audio.progress, startDate)
                    if ((data.duration - data.currentPosition) == 0) {
                        console.log("audio end")
                        player.stop()
                        control.audio.isPlayer = true
                        that.setData({
                            control: control
                        })
                        that.audioProgressAnimation(0, control.audio.progress, "00:00")
                    } else {
                        //that.audioProgressAnimation(actWidth, control.audio.progress, startDate)
                    }
                }
            })
        }
        else {
            console.log("点击自己")
            player.event.on('timeupdate', function (data) {
                console.log("开始监听")
                if (data.status == 1) {
                    console.log(data)
                    let startDate = time.secondConvertMinute(data.currentPosition)
                    console.log(startDate)
                    let actWidth = parseFloat(data.currentPosition / data.duration)
                    console.log(actWidth)
                    that.audioProgressAnimation(actWidth, control.audio.progress, startDate)
                    if ((data.duration - data.currentPosition) == 0) {
                        console.log("audio end")
                        player.stop()
                        control.audio.isPlayer = true
                        that.setData({
                            control: control
                        })
                        that.audioProgressAnimation(0, control.audio.progress, "00:00")
                    } else {
                        //that.audioProgressAnimation(actWidth, control.audio.progress, startDate)
                    }
                }
            })

            //点击当当前的录音
            console.log("ahhh")
            // 是否播放
            if (isPlayer) {
                console.log("创建播放")
                if (player.isPaused()) {
                    console.log("继续播放")
                    player.resume()
                }
                else {
                    if (!player.isPlaying()) {
                        console.log("开始播放")
                        player.invoke(index)
                    }
                }
                console.log(player.list.current())
                control.audio.isPlayer = !isPlayer
                that.setData({
                    control: control
                })

            } else {
                if (!player.isPaused()) {
                    player.pause()
                }
                control.audio.isPlayer = !isPlayer
                that.setData({
                    control: control
                })

            }
        }
        playerCurrent = player.list.current()
        console.log(player.list.current())
    },
    //    录音播放进度条
    AudioProgress: function () {
        const that = this,
            control = that.data.control;
        let systemInfo = {}
        wx.getSystemInfo({
            success: res => {
                systemInfo = res
            }
        })
        control.audio.progress = systemInfo.screenWidth * 0.3
        this.setData({
            control: control
        })
    },
    //    录音播放进度条动画
    audioProgressAnimation: function (activeProgress, progresWidth, startDate) {
        const that = this,
            control = that.data.control,
            activePro = wx.createAnimation({}),
            aniPro = wx.createAnimation({}),
            initact = wx.createAnimation({}),
            initani = wx.createAnimation({})
        //  根据歌曲播放百分比 获取active长度
        const width = progresWidth * activeProgress
        let actWidth = parseFloat(progresWidth - width)
        activePro.width(width * 2).step()
        aniPro.width(actWidth).step()
        initact.width(0).step()
        initani.width(progresWidth).step()

        control.audio.activeProgress = activePro.export()
        control.audio.aniProgress = aniPro.export()
        control.audio.startDate = startDate
        control.audio.initActProgress = initact.export()
        control.audio.initAniProgress = initani.export()
        that.setData({
            control: control
        });
    },
    discuss: function (e) {
        if(app.isUserBound() == false){
            return false
        }
        wx.navigateTo({
            url: '../discuss/discuss?id=' + e.currentTarget.dataset.id + "&accid=" + e.currentTarget.dataset.accid
        });
    },

    // // 点击红心 发送事件
    // isheart: function(e) {
    //   let that = this,
    //     log = that.data.log,
    //     bind = e.currentTarget.dataset.bind,
    //     isHeart = log[bind].interaction.isHeart,
    //     userINfo = that.data.userInfo;
    //   if (!isHeart) {
    //     console.log(e.currentTarget.dataset.bind)
    //     log[bind].interaction.isHeart = true
    //     log[bind].interaction.heartNumber.push(userINfo.nickName)
    //   } else {
    //     log[bind].interaction.isHeart = false
    //     log[bind].interaction.heartNumber.splice(log[bind].interaction.heartNumber.indexOf(userINfo.nickName), 1)
    //   }

    //   that.setData({
    //     log: log
    //   });
    // },
    bindakarili: function (e) {
        console.log(e);
        return
    },
    // 跳转到我的个人页面
    grzy: function (e) {
        wx.navigateTo({
            url: '../grzy/grzy?id=' + e.currentTarget.dataset.accid
        })
    },
    bindMy: function () {
        wx.switchTab({
            url: '../wod/wod',
        })
    },
    bindBack: function () {
        wx.switchTab({
            url: '../index/index',
        })
    },
    binddaka: function (e) {
        if(app.isUserBound() == false){
            return false
        }

        let that = this
        if(this.data.focus =='false'){
            wx.showLoading();
            app.Post(api.wxapp.clock_group_join, {
                groupId: that.data.pkid
            }, function (res) {
                wx.hideLoading();
                if (res.code == 1) {
                    app.ShowMsg("加入成功");
                    that.setData({
                        page: 1,
                        headerPuch: []
                    });
                    if (that.data.isShuaXing == false) {
                        that.setData({
                            isShuaXing: true
                        })
                        return false;
                    }
                    that.setData({
                        userList: [],
                        groupInfo: {},
                        detailList: [],
                        page: 1,
                        size: 10,
                        user_page: 1,
                        isload_d: false,
                        isload_u: false,
                        focus:''
                    });
                    //加载圈子详情
                    that.get_group_info();
                    //加载圈子包含日记
                    that.get_detail_list();
                } else {
                    app.WxAlert(res.msg);
                }
            });
        }else {
            if (that.data.groupInfo.IsTodayClock) {
                app.WxAlert("一个圈子一天只能打一次卡");
                return;
            }
            if (!that.data.groupInfo.IsJoin) {
                app.WxAlert("您还没有加入" + that.data.groupInfo.GroupName + "圈子");
                return;
            }
            wx.navigateTo({
                url: '../clockIn/clockIn?id=' + that.data.groupInfo.Id
            });
        }
    }
    ,
    imgYu: function (event) {
        var src = event.currentTarget.dataset.src; //获取data-src
        var imgList = event.currentTarget.dataset.list; //获取data-list
        //图片预览
        wx.previewImage({
            current: src, // 当前显示图片的http链接
            urls: imgList // 需要预览的图片http链接列表
        })
        this.setData({
            isShuaXing: false
        })

    },
    audioPlay: function () {
        this.setData({
            action: {
                method: 'play'
            }
        });
    },
    videlplay: function (e) {
        let index = e.currentTarget.dataset.index
        var log = this.data.detailList;
        log[index].isMviePlayer = true;
        videoContext = wx.createVideoContext('myVideo' + index)
        videoContext.index = index
        videoContext.requestFullScreen({
            duration: 0
        })
        console.log("full")
        this.setData({
            detailList: log
        })
    },
    fullVideo: function (e) {
        let log = this.data.detailList
        console.log(e)
        console.log(e.detail.fullScreen)
        if (!e.detail.fullScreen) {
            videoContext.pause()
            log[videoContext.index].isMviePlayer = false;
            console.log("结束全屏  ")
            this.setData({
                detailList: log
            })
        }
    },
    // 跳转到我的个人页面
    grzy: function (e) {
        wx.navigateTo({
            url: '../grzy/grzy?id=' + e.currentTarget.dataset.accid
        })
        // wx.navigateTo({
        //   url: '../fenxiang/fenxiang?id=' + e.currentTarget.dataset.accid
        // })
    },
    imgLoad:function (e) {
        console.log(e)
        let screen = wx.getSystemInfoSync()

        var width = e.detail.width,
            height = e.detail.height,
            ratio = width/height
        console.log(ratio)
        var viewWidth = screen.screenWidth *0.5,
            viewHeight = viewWidth / ratio
        let detailList = this.data.detailList
        detailList[e.currentTarget.dataset.bind].img = {
            width:viewWidth,
            height:viewHeight
        }
        console.log(detailList)
        this.setData({
            detailList:detailList
        })
    },
    iphoneInfo: function () {
        let that = this
        wx.getSystemInfo({
            success: res => {
                that.setData({
                    screenWidth: res.screenWidth,
                    screenHeight: res.screenHeight
                })
                that.initCanvas();
            }
        })
    },
    initCanvas: function () {
        let that = this,
            width = that.data.screenWidth * 0.8,
            height = that.data.screenHeight * 0.75,
            dataStr = (new Time()).getStringData(), // 时间
            bgImg = {}, // 背景图
            content = {}, //文字
            cardInfo = {}, // 打卡,
            erwei = {}, //二维码
            brand = {}, // 商标
            ctx = wx.createCanvasContext('shareCanvas') // 初始化canvas背景
        bgImg.url = that.data.backImg;
        bgImg.dx = 0;
        bgImg.dy = 0;
        bgImg.x = width;
        bgImg.y = height * 0.75;
        // 初始化 时间坐标
        dataStr.rect = {
            dx: width / 2 - 26,
            dy: height * 0.2,
            x: 52,
            y: 16
        }
        dataStr.border = {
            leftTop: {
                x: width / 2 - 25,
                y: height * 0.1
            },
            rightTop: {
                x: width / 2 + 25,
                y: height * 0.1
            },
            leftBottom: {
                x: width / 2 - 25,
                y: height * 0.2
            },
            rightBottom: {
                x: width / 2 + 25,
                y: height * 0.2
            }
        }
        dataStr.monthPosi = {
            x: width / 2,
            y: height * 0.13
        }
        dataStr.dayPosi = {
            x: width / 2,
            y: height * 0.19
        }
        dataStr.weekPosi = {
            x: width / 2,
            y: height * 0.2 + 14
        }
        console.log(that.data.groupInfo)
        // 初始化打卡信息坐标
        cardInfo = {
            nameInfo: {
                url: {
                    url: that.data.cgaRef.HeadImage,
                    dx: width * 0.1 - 15,
                    dy: height - 120,
                    x: 30,
                    y: 30,
                    circleX: (width * 0.1),
                    circleY: height - 105,
                },
                content: {
                    name: that.data.cgaRef.Nickname,
                    dx: width * 0.1 + 20,
                    dy: height - 100,
                }
            },
            cardDayInfo: {
                url: {
                    dx: width * 0.1 - 10,
                    dy: height - 85,
                    x: 20,
                    y: 20,
                },
                content: {
                    name: "打卡第" + that.data.cgaRef.TotalDays + "天",
                    dx: width * 0.1 + 20,
                    dy: height - 70,
                }
            },

            cardContent: {
                url: {
                    dx: width * 0.1 - 10,
                    dy: height - 60,
                    x: 20,
                    y: 20,
                },

                content: {
                    name: that.data.groupInfo.GroupName + " 打卡",
                    dx: width * 0.1 + 20,
                    dy: height - 45,
                }
            }

        }
        // 初始化二维码坐标
        erwei = {
            url: '',
            dx: width - 90,
            dy: height - 120,
            x: 80,
            y: 80
        }
        // 初始化坐标
        brand = {
            dx: width / 2 - 40,
            dy: height - 35,
            x: 80,
            y: 30
        }
        console.log(dataStr)
        that.backImage(ctx, bgImg, dataStr, cardInfo, erwei, brand, content);

    },
    /**
     *     绘制
     **/
    backImage: function (ctx, bgImage, dataStr, cardInfo, erwei, brand, contents) {
        console.log(cardInfo)
        let that = this
        wx.getImageInfo({
            src: bgImage.url,
            success: res => {
                console.log(res)
                ctx.beginPath()
                ctx.fillStyle = "white"
                ctx.strokeStyle = "white"
                ctx.fillRect(0,0,that.data.screenWidth,that.data.screenHeight)
                ctx.drawImage(res.path, bgImage.dx, bgImage.dy, bgImage.x, bgImage.y)
                ctx.fillRect(dataStr.rect.dx, dataStr.rect.dy, dataStr.rect.x, dataStr.rect.y);
                ctx.moveTo(dataStr.border.leftTop.x, dataStr.border.leftTop.y)

                ctx.lineTo(dataStr.border.rightTop.x, dataStr.border.rightTop.y)
                ctx.moveTo(dataStr.border.leftBottom.x, dataStr.border.leftBottom.y)
                ctx.strokeStyle = "white"
                ctx.lineTo(dataStr.border.leftTop.x, dataStr.border.leftTop.y)
                ctx.moveTo(dataStr.border.rightTop.x, dataStr.border.rightTop.y)
                ctx.lineTo(dataStr.border.rightBottom.x, dataStr.border.rightBottom.y)
                ctx.moveTo(dataStr.border.rightBottom.x, dataStr.border.rightBottom.y)
                ctx.lineTo(dataStr.border.leftBottom.x, dataStr.border.leftBottom.y)
                ctx.stroke()
                ctx.save()

                ctx.setTextAlign('center')
                ctx.setFillStyle('white')
                ctx.font = "bold " + '12' + "px sans-serif"
                ctx.fillText(dataStr.monthStr, dataStr.monthPosi.x, dataStr.monthPosi.y)

                ctx.setTextAlign('center')
                ctx.setFillStyle('white')
                ctx.font = "bold " + '25' + "px sans-serif"
                ctx.fillText(dataStr.day, dataStr.dayPosi.x, dataStr.dayPosi.y)
                ctx.setTextAlign('center')
                ctx.setFillStyle('#201d1d')
                ctx.font = "bold " + '13' + "px sans-serif"
                ctx.fillText(dataStr.weekStr, dataStr.weekPosi.x, dataStr.weekPosi.y)

                ctx.setTextAlign('center')
                ctx.setFillStyle('white')
                ctx.font = "bold " + '23' + "px Cursive"
                for (var i = 0; i < contents.length; i++) {
                    ctx.fillText(contents[i].con, contents[i].x1, contents[i].y1)
                }
                // ctx.fillText(content.cont2, content.x2, content.y2)
                // ctx.fillText(content.cont3, content.x3, content.y3)
                // // 二维码
                ctx.drawImage("../../images/erwei.png", erwei.dx, erwei.dy, erwei.x, erwei.y)
                //
                ctx.arc(cardInfo.nameInfo.url.circleX, cardInfo.nameInfo.url.circleY, 15, 0, Math.PI * 2, false);
                ctx.clip();
                ctx.drawImage(cardInfo.nameInfo.url.url, cardInfo.nameInfo.url.dx, cardInfo.nameInfo.url.dy, cardInfo.nameInfo.url.x, cardInfo.nameInfo.url.y)
                ctx.restore()
                ctx.setFillStyle('#201d1d')
                ctx.font = "bold " + '16' + "px sans-serif"
                ctx.fillText(cardInfo.nameInfo.content.name, cardInfo.nameInfo.content.dx, cardInfo.nameInfo.content.dy)
                ctx.drawImage("../../images/calendar2.png", cardInfo.cardDayInfo.url.dx, cardInfo.cardDayInfo.url.dy, cardInfo.cardDayInfo.url.x, cardInfo.cardDayInfo.url.y)
                ctx.setFillStyle('#999999')
                ctx.font = "bold " + '14' + "px sans-serif"
                ctx.fillText(cardInfo.cardDayInfo.content.name, cardInfo.cardDayInfo.content.dx, cardInfo.cardDayInfo.content.dy)
                ctx.drawImage("../../images/calendar2.png", cardInfo.cardContent.url.dx, cardInfo.cardContent.url.dy, cardInfo.cardContent.url.x, cardInfo.cardContent.url.y)
                ctx.fillText(cardInfo.cardContent.content.name, cardInfo.cardContent.content.dx, cardInfo.cardContent.content.dy)
                ctx.drawImage("../../images/logo.png", brand.dx, brand.dy, brand.x, brand.y)
                ctx.drawImage("../../images/xCanas.png", that.data.screenWidth*0.8-30, 0, 30, 30)
                ctx.draw()


                // ctx.setTextAlign('center');
                // ctx.setFillStyle(content.color)
                // ctx.font = "bold " + content.size + "px sans-serif"
                // ctx.fillText(content.content, content.x, content.y)
                //
                // wx.getImageInfo({
                //     src: "images/erwei.png",
                //     success: data => {
                //         ctx.drawImage(data.path, erwei.dx, erwei.dy, erwei.x, erwei.y)
                //         ctx.stroke()
                //         ctx.draw()
                //     }
                // });


            }
        });
    },
    saveImage: function () {
        wx.canvasToTempFilePath({
            canvasId: 'shareCanvas',
            success: function (res) {
                wx.saveImageToPhotosAlbum({
                    filePath: res.tempFilePath,
                    success: function () {
                        wx.showToast({
                            title: '已保存'

                        })
                    }
                })
            }
        }, this)
    },
    //获取随机图片
    get_share_info: function () {
        var that = this;
        app.Post(api.wxapp.get_share_info, {}, function (res) {
            if (res.code == 1) {
                that.setData({
                    content: res.data.ShareText,
                    backImg: res.data.ShareImage
                });
                that.iphoneInfo();
            }
        });
    },
    //获取总打卡信息
    group_calender_total: function () {
        var that = this;
        var monthList = [];
        app.Post(api.wxapp.group_calender_total, {
            groupId: that.data.pkid
        }, function (res) {
            if (res.code == 1) {
                that.setData({
                    cgaRef: res.data
                });
                that.get_share_info();
            } else if (res.code == 2) {
                wx.showModal({
                    title: '系统提示',
                    content: res.msg,
                    success: function () {
                        wx.navigateBack({
                            delta: 1
                        })
                    }
                });
            } else {
                app.WxAlert(res.msg);
            }
        });
    },
    hiddenCanvas:function (e) {
        console.log(e)
        console.log(this.data.screenWidth*0.8-70)
        if(e.changedTouches[0].x>this.data.screenWidth*0.8-75&&e.changedTouches[0].y<100){
            this.setData({
                isCanvas:'false'
            })
        }

    },
    scrollBottom:function () {
        console.log("下拉加载")
    }
})